<?php
namespace App\Http\Controllers\Map;

use App\Service\CangweiService;
use Illuminate\Http\Request;

class CangweiController extends BaseController
{
    //仓位

    //层列表
    public function getCengList(Request $request)
    {
        $shelf_id = $request->post('shelf_id', 0);
        $res = CangweiService::getCengList($shelf_id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //层修改
    public function cengModify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['title'] = $request->post('title', '');
        $pas['shelf_id'] = $request->post('shelf_id', 0);
        if ($id) {
            $res = CangweiService::cengModify($id, $pas);
        } else {
            $res = CangweiService::cengAdd($pas);
        }
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['title'] = $request->post('title', '');
        $pas['pid'] = $request->post('pid', 0);
        if ($id) {
            $res = CangweiService::modify($id, $pas);
        } else {
            $res = CangweiService::add($pas);
        }
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = CangweiService::del($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}